<?php
class DI_Metadata
{
	private static $_instance = null;
	
	public static function getInstance()
	{
		if(self::$_instance == null)
		{
			self::$_instance = new self();
		}
		return self::$_instance;
	}
	
	public static function metadata($object)
	{
		$instance = self::getInstance();
		
		return $instance->getClassMetadata($object);
	}
	
	public function getClassMetadata($object)
	{
		$result = array();
		
		$reflectionClass = new ReflectionClass($object);
		
		$properties = $reflectionClass->getProperties();
		
		foreach ($properties as $property)
		{
			$propertyName = $property->getName();
		
			$propertyComment = $property->getDocComment();
		
			$pattern = '/[^a-z0-9\s@\'\(\)]/i';
			$filtered = preg_replace($pattern, '', $propertyComment);
		
		
			$pattern = '/inject\(\'([a-z0-9]+)\'\)/i';
			preg_match($pattern, $filtered, $matches);
			
			if (! empty($matches))
			{

				$result[$propertyName] = $matches[1];
			}
		}
		
		return $result;
	}
}